home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 4 / BBS in a Box - Macintosh - Volume IV (January 1992) (BBS in a Box).iso / Files / Prog / H-K / Heiarchical Menus < prev    next >
Encoding:
Text File  |  1987-07-02  |  6.5 KB  |  133 lines  |  [TEXT/MACA]

  1. (*=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=*)
  2. (*=+-+=:              Hierarchial Menus using System 4.1           :=+-+=*)
  3. (*=+-+=:                      on the Macintosh                     :=+-+=*)
  4. (*=+-+=:                                                           :=+-+=*)
  5. (*=+-+=: Author:                                  Dion Hinchcliffe :=+-+=*)
  6. (*=+-+=: Date:                                             4/29/87 :=+-+=*)
  7. (*=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=:=+-+=*)
  8.  
  9. .  In the release of System File version 4.1 for the Macintosh, routines were added to facilitate the use of hierarchial menus.  This file will attempt to describe how to use them, using techniques I discovered by "reverse engineering" a demonstration program Apple released to show off their new addition to the system file.  No guarantees concerning the accuracy of the information will be made.
  10.  
  11. NOMENCLATURE ++>
  12.   Hierarchial menu:  A sub-menu connected to a certain menu item.  It is 
  13.    displayed if the mouse pointer is held over a parent item for a short period 
  14.    of time.
  15.   Parent menu:  The menu to which a parent item belongs.
  16.   Parent item:  All hierarchial menus must belong to a certain item in a 
  17.    connecting menu.  This item, when selected, causes the hierarchial menu 
  18.    indicated in character marking item field of the currently selected menu item 
  19.    to be called up and displayed on the screen.
  20.   Child menu:  A hierarchial menu; a menu connected to an item in a previous 
  21.    menu.
  22.  
  23. .  When using hierarchial menus, there are a few things to keep in mind:
  24.  
  25.  o  All hierarchial menu must "belong" to a regular old-style menu which is
  26.     connected to the the menu bar.
  27.  o  All hierarchial menus must have a resource ID in the range of $F6 to $FF
  28.     inclusive (246 to 255 decimal).
  29.  o  The title of all hierarchial menus must be three bytes long, the first two 
  30.     bytes being '$F' and the last being the hex digit corresponding to the last 
  31.     number in the resource ID of the hierarchial menu.  For example, a 
  32.     hierarchial menu with resource ID number 246 would have the title of '$F6'.
  33.  o  Hierarchial menus are linked to menu items in the parent menu through the 
  34.     character marking item field of a menu item.  Say that, for some reason, you 
  35.     wish to connect a hierarchial menu with resource number 255 to a certain 
  36.     item in a particular menu in your program; just change the character marking 
  37.     item number from 0 (the standard value) to 255.
  38.  
  39. HIERARCHIAL MENU RESOURCES ++>
  40. .  The structure of resource files for hierarchial menus is just the same for other menus other than the name and numbering method described above.  Connecting the menus in a hierarchial manner can prove a little tricky but not really difficult.  First, to create a parent menu, you must have at least one item in the menu which is connected to a child menu through little "flags" in the menu item definition.  These flags are set up as follows:
  41.  
  42.  o  The text field of the menu item must be terminated by the hex value of $C9 
  43.     (201 decimal).
  44.  o  The keyboard equivalent field must be set to $1B (27 decimal), commonly 
  45.     known as the ESCAPE key.
  46.  o  The character marking item field must hold the resource ID number of the 
  47.     child menu.  Remember the value must be in the range of $F6 to $FF (246 to 
  48.     255 decimal).
  49.  
  50. INSERTING HIERARCHIAL MENUS INTO THE MENU BAR ++>
  51. .  To insert hierarchial menu, insert all other normal menus first.  After this is done, insert all the hierarchial menus, connecting them to their parents by using following InsertMenu call (the specifics of the connection are handled by the computer):
  52.  
  53. -->  InsertMenu(MenuHandle,-1);   (* Insert hierarchial menu *)
  54.  
  55. .  Note: Then -1 value seems to be significant in some way, otherwise the InsertMenu call is standard.  Of course, after everything is placed into the menu, don't forget to the draw the menu bar (DrawMenuBar).
  56.  
  57. DEALING WITH ITEMS SELECTED IN HIERARCHIAL MENUS ++>
  58. .  Item selections are dealt with in the same way as regular menu item selections.  When a FindWindow call tells you there has been a menu selection, the Event Manager message will contain the resource ID of the selected menu.  If the selection has been in a hierarchial menu, then the resource ID will be within the hierarchial menu resource ID range and you should deal with it accordingly.
  59.  
  60. USING HIERARCHIAL MENUS WISELY ++>
  61. .  I have noticed that there is a certain temptation for the programmer to use hierarchial menus whenever physically possible.  However, I think this would probably be somewhat confusing to the average user.  The wisest course of action would be to use them only as necessary, such as when the menu is running out of room, especially when it contains items that contain a common theme which would allow them to be grouped in a separate sub-menu.  The example which comes most easily to mind would be the font style menu for most graphics and word processor programs.  When in doubt, use regular menus.
  62.  
  63. .  As a programming aid, I am including the decompiled menu resource from Apple's DAMenus demonstration program.  Here it is, using the C structure format used in the ResTools resource decompiler:
  64.  
  65. (* Note: The resource numbers in the header of each resource (except for the first), are different than the resource IDs in the body of the definition because of the structure of the owned resources in the desk accessory to which they belonged *)
  66.  
  67.  resource  'MENU' (-16000)
  68. {
  69.     -16000,
  70.     0,
  71.     0x7fffffbb,
  72.     disabled,
  73.     "DAMenu Tester",
  74.     {
  75.     "About DAMenu\0xc9", 0, 0, 0, 0;
  76.     "-", 0, 0, 0, 0;
  77.     "To Level 2\0xc9", 0, 27, 246, 0;
  78.     "Item 1-A", 0, 65, 0, 0;
  79.     "Item 1-B", 0, 66, 0, 0;
  80.     "-", 0, 0, 0, 0;
  81.     "Quit", 0, 81, 0, 0
  82.     }
  83. };
  84.  
  85. resource  'MENU' (-15999)
  86. {
  87.     246,
  88.     0,
  89.     0x7fffff6b,
  90.     disabled,
  91.     "$F6",
  92.     {
  93.     "Item 2-C", 0, 0, 0, 0;
  94.     "-", 0, 0, 0, 0;
  95.     "To Level 3a\0xc9", 0, 27, 247, 0;
  96.     "-", 0, 0, 0, 0;
  97.     "Item 2-D", 0, 0, 0, 0;
  98.     "Item 2-E", 0, 0, 0, 0;
  99.     "-", 0, 0, 0, 0;
  100.     "To Level 3b\0xc9", 0, 27, 248, 0
  101.     }
  102. };
  103.  
  104. resource  'MENU' (-15998)
  105. {
  106.     247,
  107.     0,
  108.     0x7fffffff,
  109.     disabled,
  110.     "$F7",
  111.     {
  112.     "Item 3a-F", 0, 0, 0, 0;
  113.     "Item 3a-G", 0, 0, 0, 0
  114.     }
  115. };
  116.  
  117. resource  'MENU' (-15997)
  118. {
  119.     248,
  120.     0,
  121.     0x7fffffff,
  122.     disabled,
  123.     "$F8",
  124.     {
  125.     "Item 3b-H", 0, 0, 0, 0;
  126.     "Item 3b-I", 0, 0, 0, 0
  127.     }
  128. };
  129.  
  130. .  If you have any questions, or would like to point out any inaccuracies, please contact me on CompuServe at user ID number 74055,1121.  Distribute this file freely to any information service or bulletin board.
  131.  ==> Dion Hinchcliffe
  132.  
  133.